package com.djl.sqtg.controller;

import com.djl.sqtg.entity.Coupon;
import com.djl.sqtg.entity.LayuiResultData;
import com.djl.sqtg.entity.LightDeals;
import com.djl.sqtg.service.ICouponService;
import com.djl.sqtg.service.ILightDealsService;
import com.djl.sqtg.util.DateUtil;
import com.djl.sqtg.util.JsonResult;
import com.djl.sqtg.util.TencentCOSUtil;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

@RestController
@RequestMapping("lightdeals")
public class LightDealsController extends BaseController{
    @Autowired
    private ILightDealsService lightDealsService;

    @RequestMapping({"getAllLightdeals"})
    public LayuiResultData getAllLightdeals(@RequestParam(required=false,defaultValue="1") int page,
                                        @RequestParam(required=false) int limit
    ){
        System.out.println("进入秒杀活动");
        List<LightDeals> lightDeals;
        Integer count;
        LayuiResultData data = new LayuiResultData();
            // 使用Pagehelper传入当前页数和页面显示条数会自动为我们的select语句加上limit查询
            // 从他的下一条sql开始分页
            PageHelper.startPage(page, limit);
            lightDeals=lightDealsService.getAllLightdeals();
            count=lightDealsService.getAllLightdealsNum();
            data.setCount(count);
            data.setData(lightDeals);
        System.out.println(data);
        return data;

    }

    @GetMapping({"updateLightdealsState/{lid}/{state}"})
    public JsonResult updateLightdealsState(@PathVariable Integer lid, @PathVariable Integer state){
            lightDealsService.updateLightdealsState(lid,state);
            return new JsonResult(OK);
    }

    @PostMapping("addLightdeals")
    public JsonResult  addLightdeals(LightDeals lightDeals) {
        System.out.println("添加秒杀活动");
        System.out.println(lightDeals.toString());
        lightDealsService.addLightdeals(lightDeals);
        return new JsonResult(OK);
    }
    @PostMapping("editLightdeals")
    public JsonResult  editLightdeals(LightDeals lightDeals) {
        System.out.println("编辑秒杀活动");
        System.out.println(lightDeals.toString());
        lightDealsService.editLightdeals(lightDeals);
        return new JsonResult(OK);
    }

}
